﻿using AutoMapper;
using MediatR;
using S.Organization.API.Application.Command.FieldSettingCommand;
using S.Organization.Domian.Model;
using S.Organization.Infrastructure;

namespace S.Organization.API.Application.CommandHandler.FieldSettingCommandHandler
{
    public class UpdFieldSettingCommandHandler : IRequestHandler<UpdFieldSettingCommand, int>
    {
        private readonly IBaseRepository<FieldSetting> _repository;
        private readonly IMapper mapper;

        public UpdFieldSettingCommandHandler(IBaseRepository<FieldSetting> repository, IMapper mapper)
        {
            _repository = repository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(UpdFieldSettingCommand request, CancellationToken cancellationToken)
        {
            return await _repository.UpdateAsync(mapper.Map<FieldSetting>(request));
        }
    }
}
